﻿using System;

namespace IFD2
{
    public partial class FltCandidate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ACL"].ToString().IndexOf("IA2") < 0)
                {
                    Response.Redirect("unauthorized.aspx");
                }
                lblAirline.Text = Session["AIRLINE"].ToString();
                if (Request.QueryString["flt_no"] != null)
                {
                    txtFltNo.Text = Request.QueryString["flt_no"].ToString();
                    txtFltDate.Text = Convert.ToDateTime(Request.QueryString["flt_date"].ToString()).ToShortDateString();
                    GridView1.DataBind();
                }
                else
                {
                    if (Session["FLT_NO"] != null)
                        txtFltNo.Text = Session["FLT_NO"].ToString();
                    if (Session["FLT_DATE"] != null)
                        txtFltDate.Text = Convert.ToDateTime(Session["FLT_DATE"].ToString()).ToShortDateString();
                    GridView1.DataBind();
                }
            }
        }

        protected void lbtnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime.Parse(txtFltDate.Text);
            }
            catch
            {
                lblError.Text = "Invalid date format!";
                txtFltDate.Text = "";
                return;
            }

            Session["FLT_NO"] = txtFltNo.Text;
            Session["FLT_DATE"] = txtFltDate.Text;
            GridView1.DataBind();
        }
    }
}